package tchk.xyz.lingyuntutorminiprogram.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tchk.xyz.lingyuntutorminiprogram.dto.TeacherCardDTO;
import tchk.xyz.lingyuntutorminiprogram.dto.TeacherDetailDTO;
import tchk.xyz.lingyuntutorminiprogram.dto.TeacherSearchDTO; // [新增] 导入
import tchk.xyz.lingyuntutorminiprogram.entity.TeacherSchedule;
import tchk.xyz.lingyuntutorminiprogram.service.ITeacherInfoService;
import tchk.xyz.lingyuntutorminiprogram.service.ITeacherScheduleService;
import tchk.xyz.lingyuntutorminiprogram.utils.Result;

import java.util.List;

@RestController
@RequestMapping("/api/public")
public class PublicController {

    @Autowired
    private ITeacherInfoService teacherInfoService;
    @Autowired
    private ITeacherScheduleService scheduleService;

    /**
     * [核心修改] 分页搜索教师列表接口
     * 使用 TeacherSearchDTO 接收所有查询参数
     */
    @GetMapping("/teachers")
    public Result<IPage<TeacherCardDTO>> searchTeachers(TeacherSearchDTO searchDTO) {
        // 直接将DTO传递给Service层
        IPage<TeacherCardDTO> resultPage = teacherInfoService.searchTeachers(searchDTO);
        return Result.success(resultPage);
    }

    /**
     * [新增] 获取教师公开详情信息接口
     */
    @GetMapping("/teacher/{userId}")
    public Result<TeacherDetailDTO> getTeacherPublicDetail(@PathVariable Long userId) {
        TeacherDetailDTO detailDTO = teacherInfoService.getTeacherPublicDetailById(userId);
        return Result.success(detailDTO);
    }

    /**
     * [新增] 获取某个老师某一周的日程
     *
     * @param userId 教师ID
     * @param date   "YYYY-MM-DD" 格式的日期字符串
     */
    @GetMapping("/teacher/{userId}/schedule")
    public Result<List<TeacherSchedule>> getSchedule(@PathVariable Long userId, @RequestParam String date) {
        List<TeacherSchedule> schedules = scheduleService.getScheduleForWeek(userId, date);
        return Result.success(schedules);
    }
}